const http = require("http");

const options = {
  hostname: `postback.komicomic.com`,
  port: 80,
  path: "/record/record",
  method: "POST"
};

// req.on("error", e => {
//   console.error(`请求遇到问题: ${e.message}`);
// });

// const postData = querystring.stringify({
//   operator_code: "310260",
//   task_id: "12345"
// });

module.exports = async postData => {
  return await new Promise(resolve => {
    const req = http.request(options, res => {
      res.resume();
      res.setEncoding("utf8");
      res.on("data", chunk => {
        resolve(chunk);
      });
    });
    req.setHeader("Content-Type", "application/json");

    req.write(JSON.stringify(postData));
    req.end();
  });
};
